package com.parkingspace.controller;


import com.parkingspace.entity.ParkingInformation;
import com.parkingspace.service.IParkingInformationService;
import com.parkingspace.util.Constants;
import com.parkingspace.util.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 车位信息表 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/parking-information")
public class ParkingInformationController {

	@Resource
	private IParkingInformationService iParkingInformationService;

	/**
	 * 查询某用户所对应的所有车位状态,也可以不传入用户ID对应所有的车位,还可以条件查询
	 * @param token 传入令牌
	 * @param current 当前第几页
	 * @param size 每页显示条数
	 * @param propertyId 传入物业ID
	 * @param parkingInformation 车位查询条件封装实体类
	 * @return 返回Map map中物业的信息存储在wuye,业主的信息存储在yezhu
	 * @throws Exception
	 */
	@GetMapping("/findAllIn")
	public ResultVO findAllIn (String token,
	                          @RequestParam(defaultValue = "1")long current,
	                          @RequestParam(defaultValue = "10") long size,
	                          Long propertyId,
	                          ParkingInformation parkingInformation) {
		try {
			Map<Object, Object> allIn = iParkingInformationService.findAllIn(token, current, size, propertyId, parkingInformation);
			return new ResultVO(Constants.OPER_SUCCESS,"请求成功!",allIn);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_FAILURE,e.getMessage(),"请求失败!");
		}
	}

	/**
	 * 上架车位功能
	 * @param parkingId 传入车位ID
	 * @param status 传入上架的状态码, （车位状态）	0 停用	1 个人私有	2 待出租	3 已出租	4 查封
	 * @param rent 传入上架价格
	 * @return 返回Boolean
	 * @throws Exception
	 */
	@PutMapping("/shelfSpace/{token}/{parkingId}/{status}/{rent}")
	public ResultVO shelfSpace (@PathVariable("token") String token, @PathVariable("parkingId") Long parkingId, @PathVariable("status") Integer status, @PathVariable("rent") double rent) {
		try {
			Boolean aBoolean = iParkingInformationService.shelfSpace(token, parkingId, status, rent);
			return new ResultVO(Constants.OPER_SUCCESS, "上架车位成功!",aBoolean);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_FAILURE, e.getMessage(),false);
		}
	}

	/**
	 * 下架车位功能
	 * @param parkingId 传入车位ID
	 * @return 返回Boolean
	 */
	@PutMapping("/shelvesParking/{parkingId}")
	public ResultVO shelvesParking (@PathVariable("parkingId") Long parkingId) {
		try {
			Boolean aBoolean = iParkingInformationService.shelvesParking(parkingId);
			return new ResultVO(Constants.OPER_SUCCESS, "下架车位成功!",aBoolean);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_FAILURE, e.getMessage(),false);
		}
	}



}

